//导入request.js请求工具
import request from '@/utils/request.js'

// 提供调用教师登录接口的函数
export const teacherLoginService = (loginData) => {
  // 使用URLSearchParams来构建表单数据
  const params = new URLSearchParams();
  params.append('employeeId', loginData.employeeId);  // 工号参数
  params.append('password', loginData.password);
  return request.post('/teacher/login', params, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'  // 设置Content-Type为表单格式
    }
  });
}

// 教师注册接口
export const teacherRegisterService = (registerData) => {
  return request.post('/teacher/register', registerData, {
    headers: {
      'Content-Type': 'application/json'  // 注册使用JSON格式
    }
  });
}

// 检查工号是否已存在
export const checkEmployeeIdService = (employeeId) => {
  return request.get('/teacher/checkEmployeeId', {
    params: {
      employeeId: employeeId
    }
  });
}

// 检查身份证号是否已存在
export const checkIdCardService = (idCard) => {
  return request.get('/teacher/checkIdCard', {
    params: {
      idCard: idCard
    }
  });
}

// 检查手机号是否已存在  
export const checkPhoneService = (phone) => {
  return request.get('/teacher/checkPhone', {
    params: {
      phone: phone
    }
  });
}

// 检查邮箱是否已存在
export const checkEmailService = (email) => {
  return request.get('/teacher/checkEmail', {
    params: {
      email: email
    }
  });
}

// 获取教师详细信息
export const getTeacherInfoService = () => {
  return request.get('/teacher/getTeacherInfo');
}

// 更新教师基本信息
export const updateBasicInfoService = (basicInfoData) => {
  return request.put('/teacher/updateBasicInfo', basicInfoData, {
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

// 更新教师个人主页
export const updatePersonalHomepageService = (personalHomepageData) => {
  return request({
    url: '/teacher/updatePersonalHomepage',
    method: 'PUT',
    data: personalHomepageData
  })
}

// 获取所有教师列表
export const getAllTeachersService = () => {
  return request({
    url: '/teacher/all',
    method: 'GET'
  })
}

// ==================== 获奖情况管理接口 ====================

// 获取教师的所有获奖情况
export const getTeacherAwardsService = () => {
  return request.get('/teacher/awards');
}

// 添加获奖情况
export const addTeacherAwardService = (awardData) => {
  return request.post('/teacher/awards', awardData, {
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

// 更新获奖情况
export const updateTeacherAwardService = (awardId, awardData) => {
  return request.put(`/teacher/awards/${awardId}`, awardData, {
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

// 删除获奖情况
export const deleteTeacherAwardService = (awardId) => {
  return request.delete(`/teacher/awards/${awardId}`);
}

// ==================== 参赛经历管理接口 ====================

// 获取教师的所有参赛经历
export const getTeacherCompetitionsService = () => {
  return request.get('/teacher/competitions');
}

// 添加参赛经历
export const addTeacherCompetitionService = (competitionData) => {
  return request.post('/teacher/competitions', competitionData, {
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

// 更新参赛经历
export const updateTeacherCompetitionService = (competitionId, competitionData) => {
  return request.put(`/teacher/competitions/${competitionId}`, competitionData, {
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

// 删除参赛经历
export const deleteTeacherCompetitionService = (competitionId) => {
  return request.delete(`/teacher/competitions/${competitionId}`);
}

// ==================== 项目经历管理接口 ====================

// 获取教师的所有项目经历
export const getTeacherProjectsService = () => {
  return request.get('/teacher/projects');
}

// 添加项目经历
export const addTeacherProjectService = (projectData) => {
  return request.post('/teacher/projects', projectData, {
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

// 更新项目经历
export const updateTeacherProjectService = (projectId, projectData) => {
  return request.put(`/teacher/projects/${projectId}`, projectData, {
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

// 删除项目经历
export const deleteTeacherProjectService = (projectId) => {
  return request.delete(`/teacher/projects/${projectId}`);
}

// 搜索教师
export const searchTeachersService = (keyword) => {
  return request({
    url: '/teacher/search',
    method: 'GET',
    params: {
      keyword: keyword
    }
  })
}

// 获取指定教师的完整信息（包含基本信息、获奖、参赛、项目等）
export const getTeacherCompleteInfoService = (employeeId) => {
  return request({
    url: `/teacher/getCompleteInfo`,
    method: 'GET',
    params: {
      employeeId: employeeId
    }
  })
}
